{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4c39f58f",
   "metadata": {},
   "source": [
    "### 人脸识别的概念和基础\n",
    "### 人脸识别应用\n",
    "### 人脸识别实践face++"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "666b081d",
   "metadata": {},
   "source": [
    "> 1.人脸检测\n",
    "\n",
    "> 2.人脸比对 + 人脸搜索\n",
    "\n",
    "  > A.人脸集合创建\n",
    "  \n",
    "  > B."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "845273ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678861966,c5d182e5-3450-4fdf-9c4e-4a3a2f6623d2', 'time_used': 412, 'faces': [{'face_token': '02f528b81e0f70298a143c39707f52ac', 'face_rectangle': {'top': 305, 'left': 586, 'width': 223, 'height': 223}, 'attributes': {'age': {'value': 21}, 'smile': {'value': 100.0, 'threshold': 50.0}, 'emotion': {'anger': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 100.0, 'neutral': 0.0, 'sadness': 0.0, 'surprise': 0.0}, 'facequality': {'value': 93.496, 'threshold': 70.1}, 'beauty': {'male_score': 89.434, 'female_score': 88.474}, 'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.544, 'position_y_coordinate': 0.422, 'vector_x_component': 0.272, 'vector_y_component': 0.124, 'vector_z_component': 0.954}, 'right_eye_gaze': {'position_x_coordinate': 0.514, 'position_y_coordinate': 0.418, 'vector_x_component': 0.092, 'vector_y_component': 0.007, 'vector_z_component': 0.996}}}}, {'face_token': 'a3aee05438c0144420ca05b857032f8a', 'face_rectangle': {'top': 773, 'left': 194, 'width': 151, 'height': 151}, 'attributes': {'age': {'value': 21}, 'smile': {'value': 0.131, 'threshold': 50.0}, 'emotion': {'anger': 0.008, 'disgust': 0.011, 'fear': 0.008, 'happiness': 0.539, 'neutral': 93.162, 'sadness': 1.84, 'surprise': 4.433}, 'facequality': {'value': 37.732, 'threshold': 70.1}, 'beauty': {'male_score': 75.045, 'female_score': 77.333}, 'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.578, 'position_y_coordinate': 0.359, 'vector_x_component': 0.543, 'vector_y_component': -0.335, 'vector_z_component': 0.77}, 'right_eye_gaze': {'position_x_coordinate': 0.548, 'position_y_coordinate': 0.349, 'vector_x_component': 0.143, 'vector_y_component': -0.013, 'vector_z_component': 0.99}}}}], 'image_id': 'iqZCBkp0F3ygJOW/SNbmwQ==', 'face_num': 2}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('dzq.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload={\n",
    "    'api_key':'CXQao5z3g20cbIGZu_0DvivvKCrW_sHy',\n",
    "    'api_secret':'5e72pKCrd177J9IUFwkb6wfC_701HTkT',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'age,smiling,facequality,emotion,beauty,eyegaze'}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b2b7eb0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd30c346",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
